package com.tanhua.app.controller;

import com.tanhua.app.controllerservice.QuanZiService;
import com.tanhua.app.controllerservice.QuanziMQService;
import com.tanhua.domain.mongo.Publish;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
public class QuanZiController {

    @Autowired
    private QuanZiService quanZiService;


    @PostMapping(name = "发布动态",value = "/movements")
    public ResponseEntity movements(Publish publish, MultipartFile[] imageContent) throws IOException {
        return quanZiService.movements(publish,imageContent);
    }

    @GetMapping(name = "我的动态",value = "/movements/all")
    public ResponseEntity myInfo(Integer page,Integer pagesize,long userId){

        return quanZiService.findMyInfo(page,pagesize,userId);
    }

    @GetMapping(name = "好友动态",value = "/movements")
    public ResponseEntity friendsInfo(Integer page,Integer pagesize) throws IOException {
        return quanZiService.findFriendsInfo(page,pagesize);
    }

    @GetMapping(name = "大数据推荐的好友动态（查询）",value = "/movements/recommend")
    public ResponseEntity RecommendInfo(Integer page,Integer pagesize) throws IOException {
        return quanZiService.findRecommendInfo(page,pagesize);
    }











    @GetMapping(name = "分页评论内容",value = "/comments")
    public ResponseEntity pgInfo(String movementId,Integer page,Integer pagesize) throws IOException {
        return quanZiService.pgInfo(movementId,page,pagesize);
    }


    /*正式收集探花用户的行为*/
    @Autowired
    private QuanziMQService quanziMQService;

    //type=1 +1
    @GetMapping(name = "单条动态详情",value = "/movements/{id}")
    public ResponseEntity info(@PathVariable("id") String publishId) throws IOException {
        quanziMQService.snedMQ("1",publishId);
        return quanZiService.info(publishId);
    }

    //type=2  +5
    @GetMapping(name = "点赞",value = "/movements/{id}/like")
    public ResponseEntity like(@PathVariable("id") String publishId) throws IOException {
        quanziMQService.snedMQ("2",publishId);
        return quanZiService.like(publishId);
    }

    //type=3 +8
    @GetMapping(name = "喜欢",value = "/movements/{id}/love")
    public ResponseEntity love(@PathVariable("id") String publishId) throws IOException {
        quanziMQService.snedMQ("3",publishId);
        return quanZiService.love(publishId);
    }

    //type=4 +10
    @PostMapping(name = "发评论",value = "/comments")
    public ResponseEntity toInfo(@RequestBody Map<String,String> map) throws IOException {

        String publishId = map.get("movementId"); //动态id
        String comment = map.get("comment"); //评论内容
        quanziMQService.snedMQ("4",publishId);
        return quanZiService.pinglun(publishId,comment);
    }

    //type=5 -5
    @GetMapping(name = "取消点赞",value = "/movements/{id}/dislike")
    public ResponseEntity unLike(@PathVariable("id") String publishId) throws IOException {
        quanziMQService.snedMQ("5",publishId);
        return quanZiService.unLike(publishId);
    }

    //type=6 -8
    @GetMapping(name = "取消喜欢",value = "/movements/{id}/unlove")
    public ResponseEntity unLove(@PathVariable("id") String publishId) throws IOException {
        quanziMQService.snedMQ("6",publishId);
        return quanZiService.unLove(publishId);
    }

}
